/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2011
 */

package com.tech15.core.model;


import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javacommon.base.BaseEntity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;


/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "SYS_DEPT")
public class Dept extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "部门";
	public static final String ALIAS_DEPTID = "部门id";
	public static final String ALIAS_SORTNO = "排序";
	public static final String ALIAS_DEPTNAME = "部门名称";
	public static final String ALIAS_MEMO = "备注";
	public static final String ALIAS_PID = "父id";
	
	//date formats
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
    /**
     * 部门id       db_column: DEPTID 
     */ 	
	
	private Long deptid;
    /**
     * 排序       db_column: SORTNO 
     */ 	
	
	private Integer sortno;
    /**
     * 部门名称       db_column: DEPTNAME 
     */ 	
	@Length(max=30)
	private java.lang.String deptname;
    /**
     * 备注       db_column: MEMO 
     */ 	
	@Length(max=200)
	private java.lang.String memo;
    /**
     * 父id       db_column: PARENTDEPTID 
     */ 	
	private Long pid;
	//columns END


	public Dept(){
	}

	public Dept(
		Long deptid
	){
		this.deptid = deptid;
	}

	

	public void setDeptid(Long value) {
		this.deptid = value;
	}
	
	@Id @GeneratedValue(generator="custom-id")
	@GenericGenerator(name="custom-id", strategy = "increment")
	@Column(name = "DEPTID", unique = true, nullable = false, insertable = true, updatable = true, length = 22)
	public Long getDeptid() {
		return this.deptid;
	}
	
	@Column(name = "SORTNO", unique = false, nullable = true, insertable = true, updatable = true, length = 2)
	public Integer getSortno() {
		return this.sortno;
	}
	
	public void setSortno(Integer value) {
		this.sortno = value;
	}
	
	@Column(name = "DEPTNAME", unique = false, nullable = true, insertable = true, updatable = true, length = 30)
	public java.lang.String getDeptname() {
		return this.deptname;
	}
	
	public void setDeptname(java.lang.String value) {
		this.deptname = value;
	}
	
	@Column(name = "MEMO", unique = false, nullable = true, insertable = true, updatable = true, length = 200)
	public java.lang.String getMemo() {
		return this.memo;
	}
	
	public void setMemo(java.lang.String value) {
		this.memo = value;
	}
	
	@Column(name = "PID", unique = false, nullable = true, insertable = true, updatable = true, length = 22)
	public Long getPid() {
		return this.pid;
	}
	
	public void setPid(Long value) {
		this.pid = value;
	}
	private Set depts = new HashSet(0);
	public void setDepts(Set<Dept> dept){
		this.depts = dept;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "dept")
	public Set<Dept> getDepts() {
		return depts;
	}
	
	private Dept dept;
	public void setDept(Dept dept){
		this.dept = dept;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "PID",nullable = false, insertable = false, updatable = false) 
	})
	public Dept getDept() {
		return dept;
	}
	
	
	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Deptid",getDeptid())
			.append("Sortno",getSortno())
			.append("Deptname",getDeptname())
			.append("Memo",getMemo())
			.append("Pid",getPid())
			.append("Did",getPid())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getDeptid())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof Dept == false) return false;
		if(this == obj) return true;
		Dept other = (Dept)obj;
		return new EqualsBuilder()
			.append(getDeptid(),other.getDeptid())
			.isEquals();
	}
	
	private String orgInfo;
	private String name;
	private Long id;
	
	private List<SysUser> users;
	
	@Transient
	public List<SysUser> getUsers() {
		return users;
	}

	public void setUsers(List<SysUser> users) {
		this.users = users;
	}

	@Transient
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Transient
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	@Transient
	public String getOrgInfo() {
		return orgInfo;
	}

	public void setOrgInfo(String orgInfo) {
		this.orgInfo = orgInfo;
	}
	
	private Integer level;

	@Transient
	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}
	
	
	
}

